﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleFactory
{
    /// <summary>
    /// 运算对象工厂类
    /// </summary>
    public class OperationFactory
    {
        public static Operation CreateOperate(string operate) //根据传进来的运算符来决定创建什么样的对象
        {
            Operation oper = null;

            switch (operate)  //此处违反开放/封闭原则
            {
                case "+":
                    oper = new OperationAdd();
                    break;
                case "-":
                    oper = new OperationSub();
                    break;
                case "*":
                    oper = new OperationMul();
                    break;
                case "/":
                    oper = new OperationDiv();
                    break;
                case "%":
                    oper = new OperationMod();
                    break;
            }

            return oper;
        }

    }
}
